import { Direction, Navigation } from '../index.js';


let dimStr = ["§e主世界","§c下届","§3末地"];

export function buildPlXyzStr(pl){
    return `§r§b<${pl?.realName}§r§b>§f ${pl?.blockPos.x}, ${pl?.blockPos.y}, ${pl?.blockPos.z}, ${dimStr[pl?.blockPos.dimid]}`;
}

export function buildXyzStr(warp){
    return `§r§b<${warp?.name}§r§b>§f${warp.tpAllow ? '§d' : ''} ${warp?.pos?.x}, ${warp?.pos?.y}, ${warp?.pos?.z}, ${dimStr[warp?.pos?.dimid]}`;
}
export function getTimeStr(timeNum){
    let date = new Date(timeNum);
    return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
}

export const navigation = {
    has(pl){
        let res = false;
        if (Direction != null) {
            let allDir = Direction.list(pl);
            if (allDir != null && Object.keys(allDir).length != 0){
                res = true;
            }
        }
        if (Navigation != null && Navigation.has(pl.xuid)) {
            res = true;
        }
        return res;
    },
    start(pl, warp){
        this.stop(pl);
        if (Direction != null) {
            Direction.start(pl);
            Direction.add(pl, warp.pos, 'xyz_pos', "§d✿§r");
        }

        if (Navigation != null){
            Navigation.new(pl.xuid, {
                name: warp.name, 
                pos: {
                    x: warp.pos.x,
                    y: warp.pos.y,
                    z: warp.pos.z,
                    dimId: warp.pos.dimid
                }
            });
        }
    },

    stop(pl){
        if (Direction != null) {
            let allDir = Direction.list(pl);
            if (allDir != null && Object.keys(allDir).length != 0){
                Direction.del(pl, undefined, 'xyz_pos');
                Direction.stop(pl.xuid);
            }
        }

        if (Navigation != null && Navigation.has(pl.xuid)){
            Navigation.clear(pl.xuid);
            return;
        }     
    }
};
